<?php

namespace backend\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\models\JjrUserProject;


/**
 * JjrUserProjectSearch represents the model behind the search form of `backend\models\JjrUserProject`.
 */
class JjrUserProjectSearch extends JjrUserProject
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'jjr_user_id', 'jjr_project_id'], 'integer'],
            [['client_gender', 'client_real_name', 'client_mobile', 'remark', 'process', 'process_remark', 'create_time', 'update_time', 'status'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = JjrUserProject::find()->asArray()
            ->alias('up')
            ->leftJoin('yii2_jjr_project p','up.jjr_project_id=p.id')
            ->leftJoin('yii2_jjr_user u','up.jjr_user_id=u.id')
            ->select('up.status,u.real_name,up.client_gender,up.id,up.client_real_name,up.client_mobile,p.name,up.process,up.create_time,up.update_time');

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'id' => $this->id,
            'jjr_user_id' => $this->jjr_user_id,
            'jjr_project_id' => $this->jjr_project_id,
            'create_time' => $this->create_time,
            'update_time' => $this->update_time,
        ]);

        $query->andFilterWhere(['like', 'client_gender', $this->client_gender])
            ->andFilterWhere(['like', 'client_real_name', $this->client_real_name])
            ->andFilterWhere(['like', 'client_mobile', $this->client_mobile])
            ->andFilterWhere(['like', 'remark', $this->remark])
            ->andFilterWhere(['like', 'process', $this->process])
            ->andFilterWhere(['like', 'process_remark', $this->process_remark])
            ->andFilterWhere(['like', 'status', $this->status]);

        return $dataProvider;
    }
}
